from rest_framework import serializers
from .models import TokenModel


class MessageUploadSerializer(serializers.Serializer):  # 检测提交的文本

    group = serializers.CharField()
    content = serializers.CharField(max_length=1000)
    token = serializers.CharField(max_length=64)

    def validate_group(self, group):
        if len(group) > 50:
            raise serializers.ValidationError("小组名长度过长")
        return group

    def validate_token(self, token):
        if TokenModel.objects.filter(token=token).exists():
            return token
        else:
            raise serializers.ValidationError("token不存在")
